<?php
include "konek.php";
if (isset($_POST['insertsiswa'])) {
	$firstnm=$_POST['firstnm'];
	$lastnm=$_POST['lastnm'];
	$kls=$_POST['kls'];
	$email=$_POST['email'];
	$pass=$_POST['pass'];
    $username=$_POST['username'];
	$img='http://placehold.it/300x300';
	if(!ctype_alpha($_POST['username']))
	{
	 echo '<script language="javascript">alert("Salah Username!!!");document.location="../"</script>';	
	}

    elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        echo '<script language="javascript">alert("Bukan Format Email!!!");document.location="../"</script>';
	} else {
        $que = mysql_query("select id_siswa, email_sis from siswa where email_sis='$email' or username ='$username'");
        $count = mysql_num_rows($que);
        if ($count > 0) {
            echo '<script language="javascript">alert("Maaf, email atau username anda sudah terdaftar!");document.location="../"</script>';
        } else {
            $query=mysql_query("INSERT INTO siswa (first_nm, last_nm, kls, email_sis, pass_sis, img) values ('$firstnm','$lastnm','$kls','$email','$pass', '$img')");
            mkdir("../page/uploads/source/siswa/$username",077);
            echo '<script language="javascript">alert("Registrasi siswa berhasil.");document.location="../"</script>';
        }
	}
}


if (isset($_POST['insertguru'])) 
    {
    	$firstnm = $_POST['firstnm'];
    	$lastnm = $_POST['lastnm'];
    	$ttl = $_POST['ttl'];
    	$mapel = $_POST['mapel'];
        $username =$_POST['code']+$_POST['username'];
    	$email = $_POST['email'];
    	$pass = $_POST['pass'];
    	$img ='http://placehold.it/300x300';
	if(!ctype_alpha($_POST['username']))
	{
	 echo '<script language="javascript">alert("Salah Username!!!");document.location="../"</script>';	
	}
        elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) 
        {
            echo '<script language="javascript">alert("Bukan Format Email!!!");document.location="../"</script>';
    	} 
        else 
        {
            $que = mysql_query("select username from guru where username='$username' ");
            $count = mysql_num_rows($que);
            if ($count > 0 ) 
            {
                echo '<script language="javascript">alert("Maaf, username anda sudah terdaftar!");document.location="../"</script>';
            } else 
            {
                $query=mysql_query("INSERT INTO guru (first_name, last_name, ttl, mapel, username, email, pass, img)  values('$firstnm','$lastnm','$ttl','$mapel','$username','$email','$pass','$img')");
                mkdir("../page/uploads/source/guru/$username",077);
                echo '<script language="javascript">alert("Registrasi guru berhasil.");document.location="../"</script>';
            }
        }
    }
?>



